//
//  DLFooterConfimCancelView.m
//  DGGUISpaceSDK
//
//  Created by 伍明鹏 on 2019/12/20.
//

#import "DLFooterConfimCancelView.h"
#define kSetValue(key,value) key ? key : value

@interface DLFooterConfimCancelView()

@property (nonatomic, strong) UIButton *cancelBtn;
@property (nonatomic, strong) UIButton *confirmBtn;
@property (nonatomic, strong) UIView *lineView;

@end

@implementation DLFooterConfimCancelView

- (instancetype)init
{
    if (self = [super init]) {
        [self setupUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 55)]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    
    self.backgroundColor = [DLThemeAdapter backgroundColor];
    //取消
    UIButton *cancelButton = [UIButton new];
    cancelButton.backgroundColor = [[DLThemeAdapter shareInstance] dynamicColor:[UIColor whiteColor] darkColor:[UIColor colorWithHex:0x232324]];
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton setTitleColor:[[DLThemeAdapter shareInstance] dynamicColor:[UIColor colorWithHex:0x999999] darkColor:[UIColor colorWithHex:0x868686]]  forState:UIControlStateNormal];
    cancelButton.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:16.0f];
    @weakify(self);
    [[cancelButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        @strongify(self);
        if (self.cancelClick) {
            self.cancelClick();
        }
    }];
    self.cancelBtn = cancelButton;
    [self addSubview:self.cancelBtn];
    
    UIView *navLine = [UIView new];
    navLine.backgroundColor = kSetValue(self.lineColor, [[DLThemeAdapter shareInstance] dynamicColor:[UIColor colorWithHex:0xE5E5E5] darkColor:[UIColor colorWithHex:0x2D2D2E]]);
    self.lineView = navLine;
    [self addSubview:self.lineView];
    
    //取消
    UIButton *confirmButton = [UIButton new];
    confirmButton.backgroundColor = [UIColor colorWithHex:0x1CBEBC];
    [confirmButton setTitle:@"确定"  forState:UIControlStateNormal];
    [confirmButton setTitleColor:[UIColor colorWithHex:0xFFFFFF]  forState:UIControlStateNormal];
    confirmButton.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Bold" size:16.0f];
    [[confirmButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        @strongify(self);
        if (self.confirmClick) {
            self.confirmClick();
        }
    }];
    self.confirmBtn = confirmButton;
    [self addSubview:self.confirmBtn];
    
    
    
    [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.top.equalTo(self.mas_top).offset(0.5);
        make.width.mas_equalTo(self.frame.size.width/2);
        make.height.mas_equalTo(self.frame.size.height-0.5);
    }];
    
    [navLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.top.equalTo(self.mas_top);
        make.width.mas_equalTo(self.frame.size.width/2);
        make.height.mas_equalTo(0.5);
    }];
    [confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.equalTo(self);
        make.width.mas_equalTo(self.frame.size.width/2);
        make.height.mas_equalTo(self.frame.size.height);
    }];
}

#pragma mark - Lazy

- (void)setLineColor:(UIColor *)lineColor{
    _lineColor = lineColor;
    self.lineView.backgroundColor = _lineColor;
}

- (void)setCustomTintColor:(UIColor *)customTintColor{
    _customTintColor = customTintColor;
    [self.confirmBtn setBackgroundColor:_customTintColor];
}

- (void)setCancelTitle:(NSString *)cancelTitle{
    _cancelTitle = cancelTitle;
    [self.cancelBtn setTitle:_cancelTitle forState:UIControlStateNormal];
}

- (void)setConfirmTitle:(NSString *)confirmTitle{
    _confirmTitle = confirmTitle;
    [self.confirmBtn setTitle:_confirmTitle forState:UIControlStateNormal];
}

@end
